const cookie = {
  set(key, val, ops={}){
    let exp = "";
    if(ops.expires){
      const d = new Date();
      d.setDate(d.getDate() + ops.expires);
      exp = ";expires=" + d;
    }
    let path = ops.path ? ";path="+ops.path : "";
    document.cookie = `${key}=${val}${path}${exp}`;
  },
  remove(key, ops={}){
    ops.expires = -1;
    this.set(key, "", ops);
  },
  get(key){
    const arr = document.cookie.split("; ");
    for(let i=0;i<arr.length;i++){
      const a = arr[i].split("=");
      if(a[0] === key){
        return a[1];
      }
    }
    return null;
  }
}
